<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="btn1">
    <span id="btn2"></span>
    <br>
    <button id="btn">验证</button>
    <script>
        onload=function(){
            btn2.innerHTML=parseInt(Math.random()*9000+1000)
            btn2.onclick=function(){
            btn2.innerHTML=parseInt(Math.random()*9000+1000)
        }
        btn.onclick=function(){
            if(btn1.value==btn2.innerHTML){
                alert("验证成功")
            }else{
                alert("验证失败，请重试")
            }
        }
        }
        
    </script>
</body>
</html>